package forever.com.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCUtil {
	private static Connection conn = null;
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://127.0.0.1:3306/travel";
	private static final String USER = "root";
	private static final String PASSWORD = "WangDc";
	
	public static Connection getConnection() {
		try {
			Class.forName(DRIVER);
			conn = (Connection) DriverManager.getConnection(URL,USER,PASSWORD);
			if(!conn.isClosed()){
				//System.out.println("Succeeded connection to the Database");
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			
		}
		return conn;
	}
	
	public static void Close(Connection conn, PreparedStatement ps, ResultSet rs) throws SQLException{
		if(rs!=null){
			rs.close();
		}
		
		if(ps!=null){
			ps.close();
		}
		
		if(conn!=null){
			conn.close();
		}
	}
}
